package com.wei.controller;

import com.wei.pojo.question;
import com.wei.service.baseService;
import com.wei.service.questionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.script.ScriptException;
import java.util.List;

@Controller
@RequestMapping("/question")
public class questionController {
        @Autowired
        @Qualifier("questionServiceImpl")
        private questionService service;

        @Autowired
        @Qualifier("baseServiceImpl")
        private baseService service1;
        //跳转界面区域
        @RequestMapping("/toAdditionSubtraction")
        public String toAdditionSubtraction(){
             return "AdditionSubtraction";
        }

        @RequestMapping("/toMultiplicationDivision")
        public String toMultiplicationDivision(){
            return "ASMultiplicationDivision";
        }
        @RequestMapping("/toMixTure")
        public String toMixTure(){
            return "MixTure";
        }


        //查找题目区域
        @RequestMapping("/asQuestion")
        @ResponseBody
        public List<question> asQuestion(){
            List<question> questions = service.queryAllASQuestion();
            return questions;
        }
        @RequestMapping("/asmdQuestion")
        @ResponseBody
        public List<question> asmdQuestion(){
            List<question> questions = service.queryAllASMDQuestion();
            return questions;
        }
        @RequestMapping("/mixQuestion")
        @ResponseBody
        public List<question> mixQuestion(){
            List<question> questions = service.queryAllMixQuestion();
            return questions;
        }
        //更新题库
        @RequestMapping(value = "/changeAsQuestion",produces = "text/html; charset=UTF-8")
        @ResponseBody
        public String changeAsQuestion(){
            List<question> list = service1.Generate50AStopic();
            for (question question : list) {
                service.updateAsQuestion(question);
            }
            return "更新成功";
        }
        @RequestMapping(value = "/changeASMDQuestion",produces = "text/html; charset=UTF-8")
        @ResponseBody
        public String changeASMDQuestion(){
            List<question> list = service1.Generate50AMSDtopic();
            for (question question : list) {
                service.updateASMDQuestion(question);
            }
            return "更新成功";
        }
        @RequestMapping(value = "/changeMixQuestion",produces = "text/html; charset=UTF-8")
        @ResponseBody
        public String changeMixQuestion() throws ScriptException {
            List<question> list = service1.Generate50Mixtopic();
            for (question question : list) {
                service.updateMixQuestion(question);
            }
            return "更新成功";
        }

        //跳转到生成图表的界面
}
